home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 1323 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.6 KB

  1. Path: news.th-darmstadt.de!news
  2. From: Enno Sandner <enno@intellektik.informatik.th-darmstadt.de>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: [Q] same template name with template-arg-list
  5. Date: Wed, 10 Jan 1996 13:50:37 +0100
  6. Organization: Fachbereich Informatik, TH Darmstadt
  7. Message-ID: <30F3B61D.1CFBAE39@intellektik.informatik.th-darmstadt.de>
  8. References: <whlong48ht.fsf@balder.metis.no>
  9. NNTP-Posting-Host: kitz.intellektik.informatik.th-darmstadt.de
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.0b4 (X11; I; SunOS 4.1.3 sun4m)
  14.  
  15. Steinar Bang wrote:
  16. > Is it legal in the ANSI C++ draft to have something like:
  17. > template<class T> class sequence {
  18. > public:
  19. >   sequence() ;
  20. > };
  21. > template<class T, int len> class sequence {
  22. > public:
  23. >   sequence() ;
  24. > };
  25. > and have these two be different templates?
  26. > Same template name but different argument lists should give different
  27. > signatures, so I don't see any principal problem...?
  28.  
  29. No, it's (IMHO) not possible.
  30. But you can have sth. similar called 'template specialization'.
  31. For example the former template could be seen as specialization
  32. of the latter template:
  33.  
  34.     template<class T,int len> class sequence { ... };
  35.     template<class T> class sequence<T,0> { ... };
  36.  
  37. In this way you can provide a default-version of the template and
  38. one with a restricted applicability.
  39. This is for example usefull if the you use an inductive definition
  40. for a generic type, like:
  41.  
  42.     A n-dim. sequence is a sequence of (n-1)-dim. sequences
  43.     A 0-sequence is a single value.
  44.  
  45.     Enno
  46.